package com.oocl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.oocl.dao.AddressDao;
import com.oocl.pojo.Address;
import com.oocl.util.DBUtil;

public class AddressDapImpl implements AddressDao{

	@Override
	public List<Address> findAddressByNameLike(String areaName) {
		Connection connection = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		String sql = "select * from address where area like ?";
		List<Address> addrs = new ArrayList<>();
		Address address = null;
		try {
			connection = DBUtil.getConnection();
			ps = connection.prepareStatement(sql);
			ps.setString(1, areaName+"%");
			rs = ps.executeQuery();
			while(rs.next()){
				address = new Address();
				address.setId(rs.getInt(1));
				address.setAreaid(rs.getString(2));
				address.setArea(rs.getString(3));
				address.setCityid(rs.getString(4));
				addrs.add(address);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			DBUtil.release(rs, ps, connection);
		}
		return addrs;
	}

}
